// 点击P弹出新窗口查询p+o
function skipPO(key) {
	var url = window.location.href;

	var skipUrlPrev = "";
	if (url.indexOf("witspring") > -1) {
		skipUrlPrev = "http://172.16.0.132:58084/vocab/dyad_std_list.htm?tabid=24_3&typeKey=p%2Bo&arrayKey2=&arrayKey=";
	} else {
		skipUrlPrev = "http://app.witspring.net:58084/vocab/dyad_std_list.htm?tabid=24_3&typeKey=p%2Bo&arrayKey2=&arrayKey=";
	}

	skipUrlPrev += key;

	window.open(skipUrlPrev);
}

// 修改p+o对应的元素同义词
function changeElementSynonym(obj, id) {
	var elementSynonym = $(obj).val();

	var param = {
		"id" : id,
		"elementSynonym" : elementSynonym
	}

	API.dyadOCheckPChangeElementSynonym(param, function(res) {
		if (res.code == 0) {
		} else {
			alert(res.desc);
		}
	});
}

// 提交该页
function submitPage(obj) {
	if (UTIL.checkButton(obj)) {

		var ostd = "";
		$(".oStd").each(function() {
			ostd = ostd+"'"+$(this).val()+"'" + ",";
		});
		ostd = ostd.substring(0, ostd.length - 1);

		API.dyadOCheckPSubmitPage({
			"ostd" : ostd
		}, function(res) {
			if (res.code == 0) {
				window.location.reload();
				$(window).scrollTop(0);
			} else {
				alert(res.desc);
			}
			UTIL.releaseButton(obj);
		});

	}
}

// 初始化数据
function refresh(obj) {
	if (UTIL.checkButton(obj)) {
		$(obj).val("刷新中...");
		API.dyadOCheckPRefresh(function(res) {
			if (res.code == 0) {
				alert("刷新成功！");
				$(obj).val("刷新");
				window.location.reload();
				$(window).scrollTop(0);
			} else {
				alert(res.desc);
			}
			UTIL.releaseButton(obj);
		});
	}
}

function changeLevel(obj, id, level) {
	var result = level == '1' ? '2' : '1';
	API.dyadOCheckPChangeLevel({
		"id" : id,
		"level" : result
	}, function(res) {
		if (res.code == 0) {
			$(obj).html(result);
		} else {
			alert(res.desc);
		}
		UTIL.releaseButton(obj);
	});
}

function submitDyad(obj, position, o) {
	if (UTIL.checkButton(obj)) {
		var elementSynonym = $("#addDyad-" + position).attr("elementSynonym");
		var p = $("#addDyad-" + position).attr("p");

		if (!p) {
			alert("请填写p");
			UTIL.releaseButton(obj);
			return;
		}

		var param = {
			"o" : o,
			"p" : p,
			"position" : position,
			"elementSynonym" : elementSynonym
		}

		API.dyadOCheckPSubmitDyad(param, function(res) {
			if (res.code == 0) {
				window.location.reload();
			} else {
				alert(res.desc);
			}
			UTIL.releaseButton(obj);
		});
	}
}

function changeDyad(obj, position, column) {
	$("#addDyad-" + position).attr(column, $(obj).val());
}

function delStd(obj, id) {
	if (UTIL.checkButton(obj)) {
		API.dyadOCheckPDelStd({
			"id" : id
		}, function(res) {
			if (res.code == 0) {
				window.location.reload();
				$(window).scrollTop(0);
			} else {
				alert(res.desc);
			}
			UTIL.releaseButton(obj);
		});
	}
}

function changeDisplayFlag(obj, id) {

	var param = {
		"id" : id
	};
	if ($(obj).prop("checked")) {
		param.displayFlag = '1';
	} else {
		param.displayFlag = '0';
	}

	API.callInterface("/vocab/dyad_o_check_p_change_display_flag.do", param, true, function(res) {
		if (res.code != 0) {
			alert(res.desc);
		}
	});
}

function changeDisplayP(id,displayP){
	var param = {
			"id" : id,
			"displayP":displayP
		};

		API.callInterface("/vocab/dyad_o_check_p_change_display_p.do", param, true, function(res) {
			if (res.code != 0) {
				alert(res.desc);
			}else{
				window.location.reload();
			}
		});
	
	
	
}